﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using BotDetector.Core;
using System.IO;
using System.Collections.Generic;

namespace BotDetector.Tests
{
    [TestClass]
    public class DetectorBatchTextTests
    {
        private static Detector detector;

        [ClassInitialize()]
        public static void ClassInit(TestContext context)
        {
            detector = new Detector();
        }

        [TestMethod]
        public void TestForBatchBotTextWithBotTexts1()
        {
            string BotFolder1 = "batch-bot-test-1";
            List<string> spamList = new List<string>();

            foreach (string file in Directory.EnumerateFiles(BotFolder1))
            {
                spamList.Add(File.ReadAllText(file));
            }

            int correct = 0;
            foreach (string text in spamList)
            {
                double rez = detector.Classify(text);
                if (rez > 0.5) correct++;
            }

            Assert.IsTrue(correct >= 8, "Bot batch 1 - not enough correct results");
        }

        [TestMethod]
        public void TestForBatchBotTextWithBotTexts2()
        {
            string BotFolder1 = "batch-bot-test-2";
            List<string> spamList = new List<string>();

            foreach (string file in Directory.EnumerateFiles(BotFolder1))
            {
                spamList.Add(File.ReadAllText(file));
            }

            int correct = 0;
            foreach (string text in spamList)
            {
                double rez = detector.Classify(text);
                if (rez > 0.5) correct++;
            }

            Assert.IsTrue(correct >= 8, "Bot batch 2 - not enough correct results");
        }

        [TestMethod]
        public void TestForBatchBotTextWithNonBotTexts1()
        {
            string BotFolder1 = "batch-nonbot-test-1";
            List<string> spamList = new List<string>();

            foreach (string file in Directory.EnumerateFiles(BotFolder1))
            {
                spamList.Add(File.ReadAllText(file));
            }

            int correct = 0;
            foreach (string text in spamList)
            {
                double rez = detector.Classify(text);
                if (rez < 0.5) correct++;
            }

            Assert.IsTrue(correct >= 24, "Nonbot batch 1 - not enough correct results");
        }

        [TestMethod]
        public void TestForBatchBotTextWithNonBotTexts2()
        {
            string BotFolder1 = "batch-nonbot-test-2";
            List<string> spamList = new List<string>();

            foreach (string file in Directory.EnumerateFiles(BotFolder1))
            {
                spamList.Add(File.ReadAllText(file));
            }

            int correct = 0;
            foreach (string text in spamList)
            {
                double rez = detector.Classify(text);
                if (rez < 0.5) correct++;
            }

            Assert.IsTrue(correct >= 16, "Nonbot batch 2 - not enough correct results");
        }
    }
}
